/**
 * 动态生成的路由
 * */
export function routerRender(data) {
  let indexRouter = [
    {
      path: '/',
      name: 'BasicLayouts',
      component: resolve => require(['../views/Layouts/BasicLayouts'], resolve),
      redirect: '/index',
      children: [...childRouterRender(data)]
    }
  ]
  return indexRouter
}
/**
 * 生成嵌套路由
 * */
function childRouterRender(data) {
  const routers = []
  for (let item of data) {
    let component = item.component
    let componentPath = ''
    componentPath = resolve => require(['@/' + component + '.vue'], resolve)
    let menu = {
      path: item.path,
      name: item.name,
      component: componentPath,
      beRoute: item.beRoute !== 0,
      beHide: item.beHide !== 0,
      meta: {
        title: item.title,
        icon: item.icon,
        url: item.path,
        outLink: item.outLink !== 0,
        componentName: item.name
      }
    }
    if (item.children && item.children.length > 0) {
      menu.children = [...childRouterRender(item.children)]
    }
    if (item.beRoute && item.beRoute === 0) {
      console.log('不生成路由')
    } else {
      routers.push(menu)
    }
  }
  return routers
}
